<?php


/** ensure this file is being included by a parent file */
defined('_JEXEC') or die('Restricted access');

		echo "<form action='{$this->formAction}' method='post' name='adminForm' id='adminForm' enctype='multipart/form-data'>";
		?>
		<table class="adminheading">
		<tr>
			<th class='helpdesk_fields'>
				<?php echo isset($this->pagetitle) ? $this->pagetitle : '' ?>
			</th>
		</tr>
		</table>

		<div id='onBeforeDisplay_wrapper'>
			<?php 
				$dispatcher = HelpDeskHelperPlugin::getInstance();
				$dispatcher->trigger( 'onBeforeDisplayFieldDefine', array( $this->row, $this->user ) );
			?>
		</div>                
		
		<fieldset class="adminform">
		<legend><?php echo HelpDeskText::_( 'Details' ); ?></legend>
		
		<table class="admintable">
		<tbody>
		    <tr>
		      <td class='key'><?php echo HelpDeskText::_( 'Title' ); ?>:</td>
		        <td class="input">
		        <?php echo $this->row->title; ?>
		        </td>
		    </tr>
		    <tr>
		      <td class='key'><?php echo HelpDeskText::_( 'Description' ); ?>:</td>
		        <td class="input">
		        <?php echo stripslashes( $this->row->description ); ?>
		        </td>
		    </tr>
		    <tr>
		      <td class='key'><?php echo HelpDeskText::_( 'Field Name' ); ?>:</td>
		        <td class="input">
		        <?php echo stripslashes( $this->row->db_fieldname ); ?>
		        </td>
		    </tr>
		    <tr>
		      <td class='key'><?php echo HelpDeskText::_( 'Type' ); ?>:</td>
		        <td class="input">
		        <?php echo HelpDeskHelperField::getFieldTypeTitle( $this->row->typeid ); ?>
		        </td>
		    </tr>
		</tbody>
		</table>
		</fieldset>
                
		<table class="adminlist">
		<thead>
            <tr>
                <th width="20">
                	#
                </th>
                <th width="20">
                	<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $this->items ); ?>);" />
                </th>
                <th class="title">
                	<?php echo HelpDeskHTML::sortList( HelpDeskText::_( 'ID' ), "id", $this->order_dir, $this->order, HelpDeskRequest::getVar( 'task' ) ); ?>
                </th>                
                <th class="title">
                	<?php echo HelpDeskHTML::sortList( HelpDeskText::_( 'Title' ), "title", $this->order_dir, $this->order, HelpDeskRequest::getVar( 'task' ) ); ?>
                </th>
                <th class="title">
                	<?php echo HelpDeskHTML::sortList( HelpDeskText::_( 'Parent' ), "parentid", $this->order_dir, $this->order, HelpDeskRequest::getVar( 'task' ) ); ?>
                </th>
                <th class="title">
                	<center>
                	<?php echo HelpDeskHTML::sortList( HelpDeskText::_( 'Order' ), "ordering", $this->order_dir, $this->order, HelpDeskRequest::getVar( 'task' ) ); ?>
					</center>
                </th>
                <th class="title">
                	<center>
                	<?php echo HelpDeskHTML::sortList( HelpDeskText::_( 'Published' ), "published", $this->order_dir, $this->order, HelpDeskRequest::getVar( 'task' ) ); ?>
					</center>
                </th>
                <th class="title">
                	<center>
	                <?php echo HelpDeskText::_( 'Is Required' ); ?>
	                </center>
                </th>
                <th class="title">
                	<center>
	                <?php echo HelpDeskText::_( 'Status' ); ?>
	                </center>
                </th>
            </tr>
		</thead>
        <tbody>
		<?php
        $k = 0;
        for ($i=0, $n=count( $this->items ); $i < $n; $i++)
        {
            $r =& $this->items[$i];
            $checked    = HelpDeskHTML::gridId( $i, $r->id );

			$already = HelpDeskHelperCategory::isField( $r->id, $this->row->id, '1' );	
											
			$img_u 	= isset($already->fieldid) ? 'tick.png' : 'publish_x.png';
			$alt_u 	= isset($already->fieldid) ? HelpDeskText::_( 'Access' ) : HelpDeskText::_( 'None' );
			$src_u 	= "<img src='images/{$img_u}' border='0' alt='{$alt_u}'>";
			$href_u = '<a href="javascript:void(0);" 
			onclick="return listItemTask(\'cb'. $i .'\',\'switch_define\')" title="'. HelpDeskText::_( "Switch" ) .'">
			'. $src_u .'
			</a>';

			$img_p 	= $r->published ? 'tick.png' : 'publish_x.png';
			$alt_p 	= $r->published ? HelpDeskText::_( 'Publish' ) : HelpDeskText::_( 'Unpublish' );

			$img_r 	= empty($already->required) ? '' : HelpDeskUrl::root().'/components/'._THISCOMPONENT.'/images/required_16.png';
			$alt_r 	= empty($already->required) ? HelpDeskText::_( 'Not Required' ) : HelpDeskText::_( 'Required' );
            
	        echo "<tr class='row".$k."'>";
				echo "<td>"; echo $i + 1 + $this->pagination->limitstart; echo "</td>";
				echo "<td>$checked</td>";
	            echo "<td class='noborder'>"; 
					echo stripslashes($r->id); 
				echo "</td>";
	            echo "<td class='noborder'>"; 
	                echo stripslashes($r->title);
	            echo "</td>";
	            echo "<td class='noborder'>"; 
	                echo stripslashes($r->parent_title);
	            echo "</td>";
	            echo "<td class='noborder'>";
	            	echo "<center>";
	            	echo stripslashes($r->ordering);
	            	echo "</center>"; 
	            echo "</td>";								
                    echo "<td class='noborder'>"; 
                        echo "<center>";
                        echo "<img src='images/{$img_p}' border='0' alt='{$alt_p}'>";
                        echo "</center>";
                    echo "</td>";
                    echo "<td class='noborder'>"; 
                        echo "<center>";
                        if ($img_r) 
                        {
                        	echo "<img src='{$img_r}' border='0' alt='{$alt_r}'>";	
                        }
                        echo "</center>";
                    echo "</td>";
                    echo "<td class='noborder'>"; 
                        echo "<center>";
						echo $href_u;                        
                        echo "</center>";
                    echo "</td>";
                    
	
	        echo "</tr>";
        	if (isset($r->description) && strlen($r->description) > 1)  
			{ 
		        echo "<tr class='row".$k."'>";
	            echo "<td class='topnowrap' valign='top' nowrap>";
					$text_display = "[ + ]";
					$text_hide = "[ - ]";
					$onclick = "displayDiv(\"description_{$r->id}\", \"showhidedescription_{$r->id}\", \"{$text_display}\", \"{$text_hide}\");";
					echo "<span class='href' id='showhidedescription_{$r->id}' onclick='{$onclick}'>{$text_display}</span>";
	            echo "</td>";
	            echo "<td colspan='10'>"; 
					echo "<div id='description_{$r->id}' style='display: none;'>";
					echo nl2br( stripslashes( $r->description ) );
					echo "</div>";
	            echo "</td>";
		        echo "</tr>";
			}
        $k = 1 - $k;
        }
		
		if (!$this->items) {
			echo "<tr class='row".$k."'>";
				echo "<td class='topnowrap' colspan='10'>";
				echo HelpDeskText::_( 'None' );
				echo "</td>";
			echo "</tr>";		
		}
        ?>
        </tbody>
        <tfoot>
        	<tr>
                <td colspan='10'>
                    <div class="pagination">
                    <?php echo $this->pagination->getListFooter(); ?>
                    </div>            
                </td>
            </tr>
        </tfoot>

		</table>


		<div id='onAfterDisplay_wrapper'>
			<?php 
				$dispatcher =& HelpDeskHelperPlugin::getInstance();
				$dispatcher->trigger( 'onAfterDisplayFieldDefine', array( $this->row, $this->user ) );
			?>
		</div>
		
		<p>* <?php echo HelpDeskText::_( "or" )  . " " . $this->required->image . " " . HelpDeskText::_( 'Required Field' ); ?></p>

		<input type="hidden" name="option" value="<?php echo $this->formOption; ?>" />
		<input type="hidden" name="controller" value="<?php echo $this->formController; ?>" />
		<input type="hidden" name="task" value="<?php echo $this->formTask; ?>" />
		<input type="hidden" name="id" value="<?php echo $this->formId; ?>" />
		<input type="hidden" name="boxchecked" value="" />
		<input type="hidden" name="order" value="<?php echo $this->order; ?>" />
		<input type="hidden" name="order_dir" value="<?php echo $this->order_dir; ?>" />
        
		<?php
		echo $this->formValidate;
		echo "</form>";
		?>